<!DOCTYPE HTML>
<html lang="cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
  <%include("/common/header.html",{title:''}){}%>
  <title>用户购物订单管理</title>
  <style>
  </style>
</head>
<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=IENn7ABARjQIkTeAKyh80VTkg2jYXf3K"></script>
<body>


<div class="x-nav" style="margin: 20px auto auto 15px;">
      <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
        <a href="javascript:;">首页</a><span lay-separator="">/</span>
       <a href="javascript:;">订单管理</a><span lay-separator="">/</span>
        <a><cite>购物订单管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="margin: -5px 14px 0px 0px;float:right;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3"></i>
    </a>
      </span>
</div>


<div class="layui-fluid">
  <div class="layui-card">


    <div class="layui-card-body">
      <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>

      <script type="text/html" id="table-useradmin-webuser">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-ok"></i>查看详情</a>
        {{#  if(d.status === 2){ }}
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-ok"></i>确认通过</a>
        {{#  }else if(d.status === 0){ }}
        <a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="null"><i
                class="layui-icon layui-icon-ok"></i>审核通过</a>
        {{#  }else if(d.status === 1){ }}
        <a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="null"><i
                class="layui-icon layui-icon-chat"></i>等待财务审核</a>
        {{#  }else{ }}
        <a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="null"><i
                class="layui-icon layui-icon-close-fill"></i>审核驳回</a>
        {{#  } }}

      </script>
      <script type="text/html" id="table-view-a">
        <a class="layui-btn  layui-btn-xs" lay-event="hutan"><i class="layui-icon layui-icon-form"></i>查看</a>
      </script>
    </div>
  </div>
</div>


<div class="layui-form" lay-filter="table-huyang"
     id="table-huyang"
     style="padding: 15px;display: none">
  <form class="layui-form" action="" lay-filter="component-form-element-b" id="myform1">
    <div class="layui-form-item">
      <h3 class="layui-form-label">商品信息</h3>
      <table class="layui-table" lay-size="lg">

        <thead>
        <tr>
          <th width="200">名称</th>
          <th width="40">单价</th>
          <th width="30">数量</th>
        </tr>
        </thead>
        <tbody id="yigougoods">

        </tbody>
      </table>
    </div>
  </form>
</div>

<div class="layui-form" lay-filter="layuiadmin-form-useradmin"
     id="layuiadmin-form-useradmin"
     style="padding: 15px;display: none">
  <form action class="layui-form" lay-filter="component-form-element" id="myform">

    <div class="layui-form-item">
      <label class="layui-form-label">订单编号</label>
      <div class="layui-input-inline">
        <input type="text" name="orderNo"  readonly="readonly" placeholder="" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">总价:</label>
      <div class="layui-input-inline">
        <input type="text" name="totalPrice"  readonly="readonly" placeholder="" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">用户名称:</label>
      <div class="layui-input-inline">
        <input type="text" name="buyName" readonly="readonly" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">联系方式:</label>
      <div class="layui-input-inline">
        <input type="text" readonly="readonly" name="phone" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">业务员:</label>
      <div class="layui-input-inline">
        <input type="text" name="accountname" readonly="readonly" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">购买时间:</label>
      <div class="layui-input-inline">
        <input type="text" name="buyTime" readonly="readonly"  class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">个人/企业:</label>
      <div class="layui-input-inline">
        <input type="text" name="isPerson" readonly="readonly"  class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">身份证号/社会信用代码:</label>
      <div class="layui-input-inline">
        <input type="text" name="idCard" readonly="readonly"  class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">开户行:</label>
      <div class="layui-input-inline">
        <input type="text" name="bankName" readonly="readonly"  class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">银行卡号:</label>
      <div class="layui-input-inline">
        <input type="text" name="bankNum" readonly="readonly"  class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">注册时间:</label>
      <div class="layui-input-inline">
        <input type="text" name="createDate" readonly="readonly"  class="layui-input">
      </div>
    </div>
  </form>
</div>
<script id="edgoods" type="text/html">
  {{#  layui.each(d.list, function(index, item){ }}
  <tr>
    <td>{{item.goods.goodName}}</td>
    <td>{{item.goods.price}}</td>
    <td>{{item.numbers}}</td>
  </tr>
  {{#  }); }}
</script>
<%include("/common/foot.html"){}%>
<script>

  layui.use(['index', 'table', 'form', 'laydate', 'layedit', 'AjaxCommon', 'AliangLayui'], function () {
    var $ = layui.$;
    var table = layui.table;
    var form = layui.form;
    var laydate = layui.laydate;
    var AjaxCommon = layui.AjaxCommon;
    var AliangLayui = layui.AliangLayui;

    var title = "查看购物信息";
    var size = ['100%', '100%']
    var findAll_url = 'adminorder/list/findallorder.jhtml';
    var update_url = 'system/goods/update.json';
    var confirm_url = 'adminorder/list/confirm.jhtml';
    var refuse_url = 'system/goods/refuse.json';
    var charge_url = 'system/goods/charge.json';
    var index;//定义建立富文本编辑器全局变量
    var layedit//定义富文本编辑器layedit全局变量
    var cols = [ //表头
      {field: 'orderNo', title: '订单编号'},
      {field: 'totalPrice', title: '价格'},
      {field: 'buyName', title: '购买用户', templet: "<div>{{d.sysUser.name}}</div>"},
      {field: 'phone', title: '用户联系方式', templet: "<div>{{d.sysUser.mobile}}</div>"},
      {field: 'accountname', title: '业务员'},
      {field: 'goodname', title: '购买商品', toolbar: '#table-view-a'},
      {field: 'buyTime', title: '购买时间'},
      {title: '操作', toolbar: '#table-useradmin-webuser', fixed: 'right'}
    ];


    AliangLayui.createTable(
      "#LAY-user-manage",
      "listReload",
      "#toolbarDemo",
      title,
      findAll_url,
      true,
      [10, 15, 20, 25],
      ['filter', 'print', 'exports'],
      cols,
      null
    );

    //初始化修改页面

    function loadData(data) {
      // console.log(JSON.stringify(data))
      var ret = {
        "id": data.id,
        "orderNo": data.orderNo,
        "totalPrice": data.totalPrice,
        "buyName": data.sysUser.name,
        "phone": data.sysUser.mobile,
        "accountname": data.accountname,
        "buyTime": data.buyTime,
        "bankName":data.sysUser.bankName,
        "bankNum":data.sysUser.bankNum,
        "createDate":data.sysUser.createDate,
        "isPerson":data.sysUser.isPerson==1?"企业":"个人",
        "idCard":data.sysUser.idCard
        // ""

      }
      return ret;
    }

    function initUpdateBelongTo(data) {
      layer.open({
        title: "商品详细信息",
        area: size,
        type: 1,
        content: $('#table-huyang'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
        btn: ['关闭'], //可以无限个按钮
        cancel: function (index, layero) {//取消事件
          location.replace(location.href);　//layer.open关闭刷新
        },
      });
      var laytpl = layui.laytpl;
      var ret2 = { //数据
        "list": data.detailsSet
      };
      laytpl($("#edgoods").html()).render(ret2, function (html) {
        $("#yigougoods").html(html);
      });

      layui.form.val("component-form-element", loadData(data));

    }


    //////////////////////////////////////以上是修改每个页面修改的地方
    //弹出修改页面调用初始化数据方法
    function initUpdate(data) {
      var a = layer.open({
        type: 1,
        title: title,
        content: $('#layuiadmin-form-useradmin'),
        btn: ['关闭'], //可以无限个按钮
        cancel: function (index, layero) {//取消事件
          location.replace(location.href);　//layer.open关闭刷新
        },
        success: function (layero, index) {
          layer.iframeAuto(index);
        }
      });
      layer.full(a);
      //如果是添加则重置表单，如果是编辑则给表单赋值
      if (data == 0 || data == null) {
        $('#myform')[0].reset();
        return;
      } else {
        layui.form.val("component-form-element", loadData(data));
      }


    }


    //修改页面的内容提交到后台处理
    form.on('submit(component-form-element)', function (data) {
      data.field.introduce = layedit.getContent(index);
      postUpdate(data);
      return false;
    });
    //头工具栏事件
    table.on('toolbar(LAY-user-manage)', function (obj) {
      var checkStatus = table.checkStatus(obj.config.id);
      switch (obj.event) {
        case 'add':
          initUpdate(0);
          break;
        case 'delete':
          var data = checkStatus.data;
          if (data.length > 0) {
            //var id = new Array(); //声明数组
            for (var i in data) {
              var a = data[i].id; //得到复选框的值
              postDelete(a);
            }
          } else {
            layer.msg("至少选择一个进行删除");
          }
          break;
        case 'export':
          layer.msg("导出");
          break;
      }
    });

    //点击每行右工具栏“操作”里面按钮效果
    table.on('tool(LAY-user-manage)', function (obj) {
      var data = obj.data;
      //alert(obj.event)
      if (obj.event === 'refuse') {
        layer.prompt({title: '请输入驳回原因', formType: 2}, function (text, index) {
          layer.close(index);
          $.ajax({
            url: refuse_url,
            type: "POST",
            data: {
              "id": data.id,
              "code": 1,
              "reason1": text
            },
            dataType: "json",
            success: function (ret) {
              layer.msg(ret.msg, {icon: 6});
              setTimeout(function () {
                window.location.reload();
              }, 1000);
            },
            error: function (jqXHR, textStatus, errorThrown) {
              var estr = "Page:" + window.location.pathname + ",Function: postDelete()";
              layer.open({
                title: "错误信息",
                area: ['100%', '100%'],
                type: 2,
                content: "base/error.jhtml?info=" + estr, //
                btn: ['关闭'] //可以无限个按钮
              });
            }
          });
        });
      } else if (obj.event === 'edit') {
        layer.confirm('敏感操作,请仔细检查，是否通过审核？', {
          btn: ['确认', '取消'] //按钮
        }, function () {
          $.ajax({
            url: confirm_url,
            type: "POST",
            data: {
              "id": obj.data.id
            },
            dataType: "json",
            success: function (ret) {
              if (ret == null) {
                layer.msg("失败，未知错误", {
                  icon: 5
                });
              } else {
                layer.msg("通过审核", {
                  icon: 6
                });
                layer.closeAll();
                table.reload('listReload');
              }
              return ret;
            },
            error: function (jqXHR, textStatus, errorThrown) {
              var estr = "Page:" + window.location.pathname + ",Function: postDelete()";
              layer.open({
                title: "错误信息",
                area: ['100%', '100%'],
                type: 2,
                content: "base/error.jhtml?info=" + estr, //
                btn: ['关闭'] //可以无限个按钮
              });
            }
          });
        });

      } else if (obj.event === 'view') {
        initUpdate(data);
      } else if (obj.event === 'hutan') {
        initUpdateBelongTo(data);
      }
    });


    //ajax提交删除内容
    window.postDelete = function (id) {
      AjaxCommon.ajax(delete_url, "post", "json", {"id": id}, function (ret) {
        if (ret == null) {
          layer.msg("删除失败", {
            icon: 5
          });
        } else {
          layer.msg("删除成功", {
            icon: 6
          });
          layer.closeAll();
          table.reload('listReload');
        }
        return ret;
      });
    };

    //ajax提交修改内容
    window.postUpdate = function (data) {
      var formData = new FormData();
      formData.append("data", JSON.stringify(data.field));
      // formData.append("file", $("input[name='file']")[0].files[0]);
      $.ajax({
        url: update_url,
        type: "POST",
        //traditional:true,
        data: formData,
        processData: false,
        contentType: false,
        success: function (data) {
          if (data.code == 0) {
            layer.closeAll();
            layer.msg(data.msg, {time: 600, icon: 1}, function () {
              //table.reload('listReload');
              location.replace(location.href);
            });
          } else {
            layer.msg(data.msg, {icon: 5});
          }
        },
        error: function (jqXHR, textStatus, errorThrown) {
          var estr = "Page:" + window.location.pathname + ",Function:postUpdate()";
          layer.open({
            title: "错误信息",
            type: 2,
            content: "base/error.jhtml?info=" + estr,
            btn: ['关闭'] //可以无限个按钮
          });
        }
      });
    }
  });

</script>

</body>

</html>
